

/*
 * MencatatPenyewaan.java
 *
 * Created on 24 Nov 11, 21:06:27
 */
package Transaksi;

import Kasir.FrameUtamaKasir;
import Kasir.Kasir;
import KonekDB.Koneksi;
import Mobil.Mobil;
import Mobil.MobilForm;
import Mobil.MobilKontrol;
import java.util.*;
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Astri
 */
public class MencatatPenyewaan extends javax.swing.JFrame {

    private Kasir kasir;

    /** Creates new form MencatatPenyewaan */
    public MencatatPenyewaan() {
        initComponents();

        noNotaField.setText("RM-" + ((new Date().getYear() + 1900) + "").substring(2)
                + (new Date().getMonth() + 1) + "-" + nomorNota());

        noNotaField.setEditable(false);

        dendaField.setText("0.0");
        dendaField.setEditable(false);
this.setLocationRelativeTo(this);
        
        jamText.setEditable(false);
        GregorianCalendar gc = new GregorianCalendar();
        DateChooser.setDate(gc.getTime());

        tglPinjamField.setText("" + new Date().toGMTString().substring(0, 10));
        tglPinjamField.setEditable(false);
        waktuPinjamField.setText("" + new Date().getHours());
        waktuPinjamField.setEditable(false);
        waktuKembaliField.setText(waktuPinjamField.getText());
        waktuKembaliField.setEditable(false);


        ActionListener taskPerformer = new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                String nol_jam = "";
                String nol_menit = "";
                String nol_detik = "";

                Date dt = new Date();

                int nilai_jam = dt.getHours();
                int nilai_menit = dt.getMinutes();
                int nilai_detik = dt.getSeconds();

                if (nilai_jam <= 9) {
                    nol_jam = "0";
                }

                if (nilai_menit <= 9) {
                    nol_menit = "0";
                }

                if (nilai_detik <= 9) {
                    nol_detik = "0";
                }

                String jam = nol_jam + Integer.toString(nilai_jam);
                String menit = nol_menit + Integer.toString(nilai_menit);
                String detik = nol_detik + Integer.toString(nilai_detik);

                jamText.setText(" " + jam + " : " + menit + " : " + detik + " ");

            }
        };
        new Timer(1000, taskPerformer).start();
    }

    public void setKasir(Kasir kasir) {
        this.kasir = kasir;
        IdKasirField.setText(kasir.getId_Kasir());
    }

    public final String nomorNota() {
        try {
            noNotaByBulan();
            String sql = "select * from NOTA";
            Connection konek = new Koneksi().getConnection();
            Statement stat = konek.createStatement();
            ResultSet rs = stat.executeQuery(sql);
            rs.next();


            String result = rs.getString(1);
            int no = Integer.parseInt(result);
            no++;

            sql = "" + no;
            while (sql.length() <= 3) {
                sql = "0" + sql;
            }

            sql = "update NOTA set noNota = '" + sql + "' where noNota = '" + result + "'";
            stat = konek.createStatement();
            stat.executeUpdate(sql);
            konek.close();

            return result;

        } catch (SQLException ex) {
            return "";
        }
    }

    public final void noNotaByBulan() {
        try {
            String sql = "select * from NOTA";
            Connection konek = new Koneksi().getConnection();
            Statement stat = konek.createStatement();
            ResultSet rs = stat.executeQuery(sql);
            rs.next();

            String resultMonth = rs.getString(2);
            int tgl = Integer.parseInt(resultMonth);
            String loop = "00001";

            if (tgl != new Date().getMonth() + 1) {
                sql = "update NOTA set noNota = '" + loop + "',BULAN='" + (new Date().getMonth() + 1) + "'";
                stat = konek.createStatement();
                stat.executeUpdate(sql);
                konek.close();
            }
        } catch (SQLException ex) {
        }
    }

    private void setDatePengembalian() {
        java.util.Date curent = DateChooser.getDate();
        long curentTime = curent.getTime();
        long lamaHari = Long.parseLong(lamaPinjamField.getText());
        long lama = lamaHari * (24 * 60 * 60 * 1000);
        long kembali = curentTime + lama;
        java.util.Date dateKembali = new java.util.Date(kembali);
        SimpleDateFormat spdt = new SimpleDateFormat("dd MMM yyyy");
        String aaa= spdt.format(dateKembali);
        tglKembaliField.setText(aaa);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        judulLabel = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        DateChooser = new com.toedter.calendar.JDateChooser();
        noNotaLabel = new javax.swing.JLabel();
        noNotaField = new javax.swing.JTextField();
        jamText = new javax.swing.JTextField();
        IdKasirLabel = new javax.swing.JLabel();
        IdKasirField = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        namaPenyewaLabel = new javax.swing.JLabel();
        namaPenyewaField = new javax.swing.JTextField();
        IdPenyewaLabel = new javax.swing.JLabel();
        idPenyewaField = new javax.swing.JTextField();
        alamatLabel = new javax.swing.JLabel();
        alamatField = new javax.swing.JTextField();
        teleponLabel = new javax.swing.JLabel();
        teleponField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        kodeMobilLabel = new javax.swing.JLabel();
        kodeMobilField = new javax.swing.JTextField();
        tglPinjamLabel = new javax.swing.JLabel();
        tglPinjamField = new javax.swing.JTextField();
        waktuLabel = new javax.swing.JLabel();
        waktuPinjamField = new javax.swing.JTextField();
        lamaPinjamLabel = new javax.swing.JLabel();
        lamaPinjamField = new javax.swing.JTextField();
        hariLabel = new javax.swing.JLabel();
        tglKembaliLabel = new javax.swing.JLabel();
        tglKembaliField = new javax.swing.JTextField();
        waktuLabel1 = new javax.swing.JLabel();
        waktuKembaliField = new javax.swing.JTextField();
        biayaLabel = new javax.swing.JLabel();
        biayaField = new javax.swing.JTextField();
        dendaLabel = new javax.swing.JLabel();
        dendaField = new javax.swing.JTextField();
        statusBayarLabel = new javax.swing.JLabel();
        statusComboBox = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        simpanButton = new javax.swing.JButton();
        lihatStrukButton = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();
        Back = new javax.swing.JButton();
        cekStatusButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel2.setBackground(new java.awt.Color(102, 0, 0));
        jPanel2.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(255, 255, 0)));

        judulLabel.setBackground(new java.awt.Color(102, 0, 0));
        judulLabel.setFont(new java.awt.Font("Trebuchet MS", 0, 18));
        judulLabel.setForeground(new java.awt.Color(255, 255, 0));
        judulLabel.setText("TRANSAKSI PENYEWAAN RENTAL MOBIL");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(163, 163, 163)
                .addComponent(judulLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(173, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(judulLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
        );

        jPanel3.setBackground(new java.awt.Color(0, 0, 0));
        jPanel3.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        noNotaLabel.setForeground(new java.awt.Color(255, 255, 0));
        noNotaLabel.setText("NO NOTA");

        IdKasirLabel.setForeground(new java.awt.Color(255, 255, 0));
        IdKasirLabel.setText("ID KASIR");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(noNotaLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(noNotaField, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(IdKasirLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(IdKasirField, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 177, Short.MAX_VALUE)
                .addComponent(DateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jamText, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jamText, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(DateChooser, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(noNotaLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(noNotaField, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                        .addComponent(IdKasirLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(IdKasirField, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel4.setBackground(new java.awt.Color(0, 0, 0));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Form Penyewaan", javax.swing.border.TitledBorder.RIGHT, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 255, 0))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel1.setForeground(new java.awt.Color(255, 255, 0));
        jLabel1.setText("PENYEWA");

        namaPenyewaLabel.setForeground(new java.awt.Color(255, 255, 0));
        namaPenyewaLabel.setText("Nama Penyewa");

        IdPenyewaLabel.setForeground(new java.awt.Color(255, 255, 0));
        IdPenyewaLabel.setText("ID Penyewa (SIM/KTP)");

        alamatLabel.setForeground(new java.awt.Color(255, 255, 0));
        alamatLabel.setText("Alamat");

        alamatField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                alamatFieldActionPerformed(evt);
            }
        });

        teleponLabel.setForeground(new java.awt.Color(255, 255, 0));
        teleponLabel.setText("Nomor Telepon");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel2.setForeground(new java.awt.Color(255, 255, 0));
        jLabel2.setText("TRANSAKSI");

        kodeMobilLabel.setForeground(new java.awt.Color(255, 255, 0));
        kodeMobilLabel.setText("Kode Mobil");

        kodeMobilField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                kodeMobilFieldKeyReleased(evt);
            }
        });

        tglPinjamLabel.setForeground(new java.awt.Color(255, 255, 0));
        tglPinjamLabel.setText("Tanggal Peminjaman");

        waktuLabel.setForeground(new java.awt.Color(255, 255, 0));
        waktuLabel.setText("Waktu Peminjaman");

        lamaPinjamLabel.setForeground(new java.awt.Color(255, 255, 0));
        lamaPinjamLabel.setText("Lama Peminjaman");

        lamaPinjamField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                lamaPinjamFieldKeyReleased(evt);
            }
        });

        hariLabel.setForeground(new java.awt.Color(255, 255, 0));
        hariLabel.setText("hari");

        tglKembaliLabel.setForeground(new java.awt.Color(255, 255, 0));
        tglKembaliLabel.setText("Tanggal Pengembalian");

        waktuLabel1.setForeground(new java.awt.Color(255, 255, 0));
        waktuLabel1.setText("Waktu Pengembalian");

        biayaLabel.setForeground(new java.awt.Color(255, 255, 0));
        biayaLabel.setText("Biaya Penyewaan (Rp)");

        dendaLabel.setForeground(new java.awt.Color(255, 255, 0));
        dendaLabel.setText("Denda (Rp)");

        statusBayarLabel.setForeground(new java.awt.Color(255, 255, 0));
        statusBayarLabel.setText("Status Pembayaran");

        statusComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "LUNAS", "BELUM LUNAS" }));

        jLabel3.setForeground(new java.awt.Color(255, 0, 0));
        jLabel3.setText("*dikenakan bila melebihi lama peminjaman");

        simpanButton.setText("SIMPAN");
        simpanButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                simpanButtonActionPerformed(evt);
            }
        });

        lihatStrukButton.setText("LIHAT STRUK AWAL -->");
        lihatStrukButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lihatStrukButtonActionPerformed(evt);
            }
        });

        Back.setText("Kembali");
        Back.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BackActionPerformed(evt);
            }
        });

        cekStatusButton.setText("Cek Status Mobil");
        cekStatusButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cekStatusButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(namaPenyewaLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(45, 45, 45)
                                .addComponent(namaPenyewaField, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(IdPenyewaLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(teleponLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(alamatLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 73, Short.MAX_VALUE)))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(alamatField, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                                    .addComponent(teleponField, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                                    .addComponent(idPenyewaField)))))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(tglPinjamLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                                .addComponent(lamaPinjamLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(tglKembaliLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                                .addComponent(biayaLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(dendaLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(statusBayarLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(kodeMobilLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(33, 33, 33)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(lamaPinjamField, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(hariLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(tglPinjamField, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                                            .addComponent(tglKembaliField, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                                            .addComponent(kodeMobilField, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                                            .addComponent(biayaField, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                                            .addComponent(dendaField, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE))
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel4Layout.createSequentialGroup()
                                                .addGap(18, 18, 18)
                                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                                        .addComponent(waktuLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGap(18, 18, 18)
                                                        .addComponent(waktuPinjamField, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                                        .addComponent(waktuLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                        .addComponent(waktuKembaliField, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                            .addGroup(jPanel4Layout.createSequentialGroup()
                                                .addGap(5, 5, 5)
                                                .addComponent(cekStatusButton)))))
                                .addGap(98, 98, 98))
                            .addComponent(statusComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
            .addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 638, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addComponent(Back)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 232, Short.MAX_VALUE)
                .addComponent(simpanButton)
                .addGap(18, 18, 18)
                .addComponent(lihatStrukButton)
                .addGap(52, 52, 52))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(namaPenyewaLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(namaPenyewaField, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(IdPenyewaLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(idPenyewaField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(alamatLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(alamatField, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(teleponLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addComponent(teleponField, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(kodeMobilLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(kodeMobilField, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cekStatusButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tglPinjamLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tglPinjamField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(waktuLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(waktuPinjamField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lamaPinjamLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lamaPinjamField, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(hariLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tglKembaliLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tglKembaliField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(waktuLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(waktuKembaliField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(biayaLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(biayaField, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dendaLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dendaField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusBayarLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(statusComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(simpanButton)
                    .addComponent(lihatStrukButton)
                    .addComponent(Back))
                .addGap(25, 25, 25))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void alamatFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alamatFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_alamatFieldActionPerformed

    private void lihatStrukButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lihatStrukButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_lihatStrukButtonActionPerformed

    private void simpanButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simpanButtonActionPerformed
        try {
                       
            String noNota = noNotaField.getText();
            String namaPenyewa = namaPenyewaField.getText();
            String idPenyewa = idPenyewaField.getText();
            String alamatPenyewa = alamatField.getText();
            String noTlp = teleponField.getText();
            String kodeMobil = kodeMobilField.getText();
            String tglPinjam = tglPinjamField.getText();
            int waktuPinjam = Integer.parseInt(waktuPinjamField.getText());
            int lamaPinjam = Integer.parseInt(lamaPinjamField.getText());
            String tglKembali = tglKembaliField.getText();
            int waktuKembali = Integer.parseInt(waktuKembaliField.getText());
            double totalBiaya = Double.parseDouble(biayaField.getText());
            double denda = Double.parseDouble(dendaField.getText());
            String statusBayar = statusComboBox.getSelectedItem().toString();
           
            Transaksi transaksiBaru = new Transaksi();
            transaksiBaru.setNo_Nota(noNota);
            transaksiBaru.setNama_Penyewa(namaPenyewa);
            transaksiBaru.setId_Penyewa(idPenyewa);
            transaksiBaru.setAlamat_Penyewa(alamatPenyewa);
            transaksiBaru.setNo_Tlp(noTlp);
            transaksiBaru.setKode_Mobil(kodeMobil);
            transaksiBaru.setTgl_Pinjam(tglPinjam);
            transaksiBaru.setWaktu_Pinjam(waktuPinjam);
            transaksiBaru.setLama_Pinjam(lamaPinjam);
            transaksiBaru.setTgl_Kembali(tglKembali);
            transaksiBaru.setWaktu_Kembali(waktuKembali);
            transaksiBaru.setTotal_Biaya(totalBiaya);
            transaksiBaru.setDenda(denda);
            transaksiBaru.setStatus_Bayar(statusBayar);

            TransaksiKontrol transaksiKontrol = TransaksiKontrol.getKoneksiKontrol();
            transaksiKontrol.tambahTransaksi(transaksiBaru);
            
            setUpdate();
            
            
            JOptionPane.showMessageDialog(this, " " + noNota + " berhasil ditambah");
        } catch (SQLException ex) {
            Logger.getLogger(MencatatPenyewaan.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Transaksi gagal ditambah.");
        }

        // TODO add your handling code here:
    }//GEN-LAST:event_simpanButtonActionPerformed

    private void setUpdate(){
        try {
            String sql = "select * from mobil";
            Connection konek = new Koneksi().getConnection();
            Statement stat = konek.createStatement();
            ResultSet rs = stat.executeQuery(sql);
            rs.next();
            
            String kode = kodeMobilField.getText();
           
                sql = "update mobil set Status_Mobil = '" + "Disewakan" + "'where Kode_Mobil = '" + kode + "'";
                stat = konek.createStatement();
                stat.executeUpdate(sql);
                konek.close();
            }
         catch (SQLException ex) {
        }
    }
    
    private void cekStatus() throws SQLException{
        try{
            String kode = kodeMobilField.getText();
            
            String sql = "select Status_Mobil from mobil where Kode_Mobil = '" + kode + "'";
            Connection konek = new Koneksi().getConnection();
            Statement stat = konek.createStatement();
            ResultSet rs = stat.executeQuery(sql);
                        
            if(rs.next()){                
                if(rs.getString("Status_Mobil").equals("Disewakan"))
                    JOptionPane.showMessageDialog(null, "Mobil sedang disewakan, silahkan pilih mobil lain!" );                    
            }
            if(rs.getString("Status_Mobil").equals("Tidak Disewakan"))
                JOptionPane.showMessageDialog(null, "Mobil bisa disewakan" );
        }
        catch (SQLException ex) {
        }
    }
    
    
    
    private void kodeMobilFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_kodeMobilFieldKeyReleased
        // TODO add your handling code here:
        try {
            Mobil mobil = new Mobil();
            String kode = kodeMobilField.getText();
            mobil.setKode_Mobil(kode);
                       
                                
            int lama = Integer.parseInt(lamaPinjamField.getText().toString());

            mobil = MobilKontrol.getKoneksiKontrol().cariMobil(mobil);
            Double hargaSewa = mobil.getHarga_Sewa();

            biayaField.setText(String.valueOf(lama*hargaSewa));


        } catch (Exception e) {
            Logger.getLogger(MencatatPenyewaan.class.getName()).log(Level.SEVERE, null, e);

        }


    }//GEN-LAST:event_kodeMobilFieldKeyReleased

    private void lamaPinjamFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lamaPinjamFieldKeyReleased
        // TODO add your handling code here:
        setDatePengembalian();
    }//GEN-LAST:event_lamaPinjamFieldKeyReleased

    private void BackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BackActionPerformed

        new FrameUtamaKasir().setVisible(true);
        this.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_BackActionPerformed

    private void cekStatusButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cekStatusButtonActionPerformed
        try {
            // TODO add your handling code here:
    //        new tabelStt().setVisible(true);
    //        this.setVisible(false);
            cekStatus();
        } catch (SQLException ex) {
            Logger.getLogger(MencatatPenyewaan.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_cekStatusButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MencatatPenyewaan().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Back;
    private com.toedter.calendar.JDateChooser DateChooser;
    private javax.swing.JTextField IdKasirField;
    private javax.swing.JLabel IdKasirLabel;
    private javax.swing.JLabel IdPenyewaLabel;
    private javax.swing.JTextField alamatField;
    private javax.swing.JLabel alamatLabel;
    private javax.swing.JTextField biayaField;
    private javax.swing.JLabel biayaLabel;
    private javax.swing.JButton cekStatusButton;
    private javax.swing.JTextField dendaField;
    private javax.swing.JLabel dendaLabel;
    private javax.swing.JLabel hariLabel;
    private javax.swing.JTextField idPenyewaField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextField jamText;
    private javax.swing.JLabel judulLabel;
    private javax.swing.JTextField kodeMobilField;
    private javax.swing.JLabel kodeMobilLabel;
    private javax.swing.JTextField lamaPinjamField;
    private javax.swing.JLabel lamaPinjamLabel;
    private javax.swing.JButton lihatStrukButton;
    private javax.swing.JTextField namaPenyewaField;
    private javax.swing.JLabel namaPenyewaLabel;
    private javax.swing.JTextField noNotaField;
    private javax.swing.JLabel noNotaLabel;
    private javax.swing.JButton simpanButton;
    private javax.swing.JLabel statusBayarLabel;
    private javax.swing.JComboBox statusComboBox;
    private javax.swing.JTextField teleponField;
    private javax.swing.JLabel teleponLabel;
    private javax.swing.JTextField tglKembaliField;
    private javax.swing.JLabel tglKembaliLabel;
    private javax.swing.JTextField tglPinjamField;
    private javax.swing.JLabel tglPinjamLabel;
    private javax.swing.JTextField waktuKembaliField;
    private javax.swing.JLabel waktuLabel;
    private javax.swing.JLabel waktuLabel1;
    private javax.swing.JTextField waktuPinjamField;
    // End of variables declaration//GEN-END:variables
}
